home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Games / JST / sources / src / loaders / Lemmings / lemunivhd.asm < prev    next >
Encoding:
Assembly Source File  |  2001-03-19  |  19.2 KB  |  1,089 lines

  1.  
  2. ; *** Lemmings Universal HD Loader V1.6
  3. ; *** Written by Jean-François Fabre
  4. ;
  5. ; *** a hell of a loader!!!!!!
  6.  
  7.     include    "jst.i"
  8.  
  9.     HD_PARAMS    "",0,0
  10.  
  11. MAINBASE = $78A82
  12.  
  13. VER_MORE_NTSC = 1
  14. VER_MORE_PAL = 2
  15. VER_2D_PAL = 3
  16. VER_2D_NTSC = 4
  17. VER_BUDGET = 5
  18. VER_MORE_KEI = 6
  19. VER_2D_TIMO = 7
  20.  
  21.  
  22. loader:
  23.     RELOC_MOVEL    D0,trainer
  24.  
  25.     Mac_printf    "Lemmings Universal HD Loader V1.6"
  26.     Mac_printf    "Coded by Jean-François Fabre © 1997-2000"
  27.     NEWLINE
  28.     Mac_printf    "Thanks to Keith Krellwitz, Dominic Cresswell,"
  29.     Mac_printf    "Troy Pladson, Jacob Jensen, Phil Douglas,"
  30.     Mac_printf    "Kristian Hesketh"
  31.  
  32.     RELOC_TSTL    trainer
  33.     beq    trskip$
  34.     NEWLINE
  35.     Mac_printf    "Infinite time activated"
  36. trskip$
  37.  
  38.     TESTFILE    mainname
  39.     tst.l    D0
  40.     bne    MainErr
  41.  
  42.     move.l    #2000,D0
  43.     JSRABS    LoadSmallFiles
  44.  
  45.     move.l    #$80000,D0
  46.     JSRABS    AllocExtMem
  47.     RELOC_MOVEL    D0,ExtBase
  48.     beq    noext$
  49.  
  50.     RELOC_MOVEL    #$80000,ExtSize
  51.  
  52.     move.l    ExtBase(pc),D0
  53.     cmp.l    #$80000,D0
  54.     beq    onemegchip$
  55.     
  56.     RELOC_MOVEL    #$00F,ExtFlag
  57.     bra    suite$
  58.  
  59. onemegchip$
  60.     RELOC_MOVEL    #$F00,ExtFlag
  61.     bra    suite$
  62.  
  63.     ; *** only the 512K chipmem used
  64. noext$
  65.     RELOC_CLRL    ExtSize
  66.     RELOC_CLRL    ExtFlag
  67.     RELOC_CLRL    ExtBase
  68.  
  69. suite$
  70.  
  71.     bsr    GetVersion
  72.  
  73.     moveq.l    #0,D0
  74.     move.l    #CACRF_CopyBack,D1
  75.     JSRABS    Degrade
  76.  
  77.     GO_SUPERVISOR
  78.     SAVE_OSDATA    $80000
  79.  
  80.     lea    $DFF000,A6
  81.     move.w    #$7FFF,dmacon(A6)
  82.     move.w    #$7FFF,intena(A6)
  83.  
  84.     move.w    #$FFFF,bltafwm(A6)    ; set blitter masks to all ones
  85.     move.w    #$FFFF,bltalwm(A6)    ; ""
  86.  
  87. BootGame:
  88.     move.l    #MAINBASE,A1
  89.     lea    mainname(pc),a0
  90.     moveq    #0,D0
  91.     moveq    #-1,D1
  92.     JSRGEN    ReadFile
  93.  
  94.     bsr    PatchMain
  95.  
  96.     JSRGEN    FlushCachesHard
  97.  
  98.     move.l    ExtBase(pc),4.W
  99.     MOVE.L    ExtSize(pc),8.W
  100.     MOVE.l    ExtFlag(pc),D2
  101.  
  102.     JMP    MAINBASE+$4E
  103.  
  104. PatchMain:
  105.     move.l    version(pc),D0
  106.     cmp.l    #VER_BUDGET,D0
  107.     beq    PatchMain_Budget
  108.     cmp.l    #VER_MORE_NTSC,D0
  109.     beq    PatchMain_MoreNTSC
  110.     cmp.l    #VER_2D_PAL,D0
  111.     beq    PatchMain_2DPAL
  112.     cmp.l    #VER_2D_TIMO,D0
  113.     beq    PatchMain_2DTIMO
  114.  
  115.     lea    VerErr2(pc),A0
  116.     JSRGEN    SetExitRoutine
  117.     JSRGEN    InGameExit
  118. loop$
  119.     move.w    #$F00,$DFF180
  120.     bra    loop$
  121.  
  122.  
  123. PatchMain_Budget:
  124.     ; *** removes country check (PAL/NTSC)
  125.  
  126.     move.l    #$4E714E71,$2F2+MAINBASE
  127.  
  128.     ; *** disk routine
  129.  
  130.     PATCHUSRJMP    $92A+MAINBASE,DiskRoutine
  131.  
  132.     ; *** main program
  133.  
  134.     PATCHUSRJMP    $1C0+MAINBASE,PatchCode_Budget
  135.     rts
  136.  
  137. PatchMain_MoreNTSC:
  138.     ; *** Adjusts PAL version to NTSC
  139.  
  140.     move.l    #MAINBASE,A0
  141.  
  142.     cmp.w    #$2C81,($A6,A0)
  143.     beq    ntscver$
  144.  
  145.     RELOC_MOVEL    #VER_MORE_PAL,version
  146.  
  147.     move.w    #$2C81,($A6,A0)        ; patch from NTSC->PAL
  148.     move.w    #$F4C1,($AC,A0)        ; so main files are identical
  149.     move.l    #$4E7560FE,($36A,A0)
  150.  
  151.     PATCHUSRJMP    $22A+MAINBASE,PatchCode_MorePAL
  152.  
  153.  
  154.     bra    cont$
  155. ntscver$
  156.     ; *** main program
  157.  
  158.     PATCHUSRJMP    $22A+MAINBASE,PatchCode_MoreNTSC
  159.  
  160. cont$
  161.     ; *** it can be the DOS version. Be careful
  162.  
  163.     cmp.w    #$00C0,($238,A0)
  164.     bne    protected$
  165.  
  166.     ; *** it is the DOS version
  167.  
  168.     RELOC_MOVEL    #VER_MORE_KEI,version
  169.  
  170.     PATCHUSRJMP    $9DC+MAINBASE,DiskRoutine
  171.  
  172.     ; *** removes country check (PAL/NTSC)
  173.  
  174.     move.w    #$4E75,$362+MAINBASE
  175.  
  176.     rts
  177.  
  178. protected$
  179.  
  180.     ; *** removes country check (PAL/NTSC)
  181.  
  182.     move.l    #$4E714E71,$362+MAINBASE
  183.  
  184.  
  185.     ; *** disk routine
  186.  
  187.     PATCHUSRJMP    $9E2+MAINBASE,DiskRoutine
  188.  
  189.     rts
  190.  
  191. PatchMain_2DPAL:
  192.     ; *** correct NTSC version to PAL
  193.  
  194.     lea    MAINBASE,A0
  195.     move.l    #$4E754E75,($792,A0)    ; remove country check
  196.  
  197.  
  198.     cmp.w    #$3D7C,($464,A0)
  199.     beq    palver$
  200.  
  201.     RELOC_MOVEL    #VER_2D_NTSC,version
  202.  
  203.     move.l    #$3D7C4681,($464,A0)
  204.     move.w    #$0EC1,($46C,A0)
  205.     move.w    #$4681,($3B1A,A0)
  206.     move.w    #$0EC1,($3B20,A0)
  207.  
  208. palver$
  209.     ; *** Main prog, common to both PAL and NTSC versions
  210.  
  211.     PATCHUSRJMP    $3BCC+MAINBASE,PatchCode_2D
  212.     PATCHUSRJMP    $3C0A+MAINBASE,PatchCode_2D_Dec
  213.  
  214.     ; *** Decrunch
  215.  
  216.     PATCHUSRJMP    $8AA+MAINBASE,Decrunch
  217.  
  218.     ; *** Country check
  219.  
  220. ;    move.l    #$4E714E71,$78A+MAINBASE
  221.  
  222.     ; *** Disk loading routine
  223.  
  224.     PATCHUSRJMP    $6B14+MAINBASE,DiskRoutine
  225.  
  226.     ; *** Pre intro patch (useless...)
  227.  
  228. ;    PATCHUSRJSR    $7907E,PatchIntro
  229. ;    PATCH_NOP    $7907E+6
  230.     rts
  231.  
  232.     IFD    BLITTERFIX
  233. PatchIntro:
  234.     JSRGEN    FlushCachesHard
  235.     btst    #6,$BFE001
  236.     rts
  237.  
  238. BlitterFix:
  239.     STORE_REGS    
  240.     lea    MAINBASE,A0
  241.     lea    $7FFF0,A1
  242.     lea    .waitblit_str(pc),A2
  243.     move.l    #8,D0
  244. .loop:
  245.     JSRGEN    HexSearch
  246.     cmp.l    #0,A0
  247.     beq.b    .end
  248.  
  249.     ; changes blitwait routine
  250.  
  251.     PATCHGENJSR    (A0),WaitBlit
  252.     PATCH_NOP    (6,A0)
  253.     bra.b    .loop
  254. .end
  255.     RESTORE_REGS
  256.     rts
  257.  
  258. .waitblit_str:
  259.     dc.l    $082E0006,$000266F8
  260.     ENDC
  261.  
  262. PatchMain_2DTIMO:
  263.     lea    MAINBASE,A0
  264.     move.l    #$4E754E75,($792,A0)    ; remove country check
  265.  
  266.  
  267.     PATCHUSRJMP    $3BCC+MAINBASE,PatchCode_2DTIMO
  268.     PATCHUSRJMP    $3C0A+MAINBASE,PatchCode_2DTIMO_Dec
  269.  
  270.     ; *** Disk loading routine
  271.  
  272.     PATCHUSRJMP    $6B14+MAINBASE,DiskRoutine
  273.     rts
  274.  
  275. PatchCode_Budget:
  276.     STORE_REGS
  277.     MOVE    #$7FFF,154(A6)        ; original game
  278.     PATCHUSRJMP    $7F32.W,DiskRoutine
  279.  
  280.     ; *** removes disk protection (motherfuckers)
  281.  
  282.     PATCHUSRJMP    $7592.W,RemoveProtect_Budget
  283.  
  284.     ; *** install quit key
  285.  
  286.     PATCHUSRJSR    $1762.W,kbint_Budget
  287.     move.w    #$4E71,$1768.W
  288.  
  289.     ; *** remove f***ing checksum codes
  290.  
  291.     bsr    RemoveChecksums
  292.     bsr    RemoveChecksums_Budget
  293.  
  294.     ; *** trainer?
  295.  
  296.     move.l    trainer(pc),d0
  297.     beq    notrain$
  298.  
  299.     move.b    #$4A,$1952.W
  300. notrain$
  301.  
  302.     RESTORE_REGS
  303.     jmp    $400.W
  304.  
  305. ; actually there are 2 PAL versions: one standalone with password
  306. ; and another one very similar to NTSC version. We have to check the
  307. ; code before patching
  308.  
  309. PatchCode_MorePAL:
  310.     ; *** check if this is the diskcheck version
  311.  
  312.     cmp.l    #$3D7C8210,$75D2.W
  313.     beq    PatchCode_MoreNTSC    ; PAL version, but same code as NTSC
  314.  
  315.     ; ok password PAL version
  316.  
  317.     ; *** trainer
  318.  
  319.     RELOC_TSTL    trainer
  320.     beq    notrain$
  321.  
  322.     move.w    #$6010,$197C.W
  323. notrain$
  324.  
  325.     ; *** the keyboard interrupt
  326.  
  327.     PATCHUSRJSR    $177C.W,kbint_Common
  328.  
  329.     ; *** the disk routine
  330.  
  331.     PATCHUSRJMP    $815C,DiskRoutine
  332.  
  333.     ; *** remove password protection
  334.  
  335.     move.b    #$60,$3058.W
  336.     move.b    #$60,$30FC.W
  337.  
  338.     JSRGEN    FlushCachesHard
  339.  
  340.     lea    $DFF000,A6
  341.     move.w    #$7FFF,dmacon(A6)
  342.     move.w    #$7FFF,intena(A6)
  343.  
  344.     jmp    $400.W
  345.  
  346.  
  347. PatchCode_MoreNTSC:
  348.     ; *** trainer
  349.  
  350.     move.l    D0,-(sp)
  351.     move.l    trainer(pc),d0
  352.     beq    notrain$
  353.  
  354.     move.w    #$6010,$197A.W
  355. notrain$
  356.     move.l    (sp)+,D0
  357.  
  358.  
  359.     PATCHUSRJMP    $7F72.W,DiskRoutine
  360.  
  361.     PATCHUSRJMP    $75D2.W,RemoveProtect_MoreNTSC
  362.     move.w    #$4E75,$3CC2.W
  363.  
  364.     PATCHUSRJSR    $177A.W,kbint_Common
  365.     move.w    #$4E71,$1780.W
  366.  
  367.     JSRGEN    FlushCachesHard
  368.  
  369.     lea    $DFF000,A6
  370.     move.w    #$7FFF,dmacon(A6)
  371.     move.w    #$7FFF,intena(A6)
  372.  
  373.     jmp    $400.W
  374.  
  375. RemoveProtect_MoreNTSC:
  376.     move.l    #$1001ff00,$8464
  377.     move.l    #$70616e65,$9cf8
  378.     move.l    #$00075578,$9d2c
  379.     move.l    #$0000017d,$9e08
  380.     move.l    #$e8ad0000,$9e20
  381.     move.l    #$0000017d,$9e34
  382.     move.l    #$3e030000,$9e50
  383.     move.l    #$00010003,$cd68
  384.     move.l    #$00200033,$14078
  385.     rts
  386.  
  387. ; *** keyboard patch (quit) for oh no more lemmings version
  388.  
  389. kbint_Trainer:
  390.     cmp.b    #$46,D0
  391.     bne    kbint_Common
  392.  
  393.     move.w    $9E5A,$9DBE    ; number of lemmings saved=maximum number
  394.  
  395.     move.b    #$45,D0        ; simulates ESC
  396.  
  397. kbint_Common:  
  398.     move.b    #0,$BFEC01
  399.     cmp.b    #$59,D0
  400.     bne    noquit$
  401.     JSRGEN    InGameExit
  402. noquit$
  403.     rts
  404.  
  405. ; *** keyboard patch (quit) for budget version
  406.  
  407. kbint_Budget:
  408.     move.b    #1,$BFEC01
  409.     cmp.b    #$59,D0
  410.     bne    noquit$
  411.     JSRGEN    InGameExit
  412. noquit$
  413.     rts
  414.  
  415. PatchCode_2DTIMO_Dec:
  416.     bsr    Decrunch        ; decrunch (original program)
  417. PatchCode_2DTIMO:
  418.     ; *** remove protection
  419.  
  420.     PATCHUSRJMP    $7638.W,RemoveProtect_2DTIMO
  421.  
  422.     bra    PatchCode_2D_Common
  423.  
  424. PatchCode_2D_Dec:
  425.     JSR    $7932C        ; decrunch (original program)
  426. PatchCode_2D:
  427.  
  428.     ; *** remove protection
  429.  
  430.     PATCHUSRJMP    $7638.W,RemoveProtect_2D
  431.  
  432. PatchCode_2D_Common:
  433.  
  434.     ; *** the trainer (infinite time)
  435.  
  436.     move.l    D0,-(sp)
  437.     move.l    trainer(pc),d0
  438.     beq    notrain$
  439.  
  440.     move.w    #$6010,$1952.W
  441. notrain$
  442.     move.l    (sp)+,D0
  443.  
  444.     ; *** remove f***ing checksum codes
  445.  
  446.     bsr    RemoveChecksums
  447.     bsr    RemoveChecksums_2D
  448.  
  449.     ; *** the keyboard interrupt
  450.  
  451.     PATCHUSRJSR    $1752.W,kbint_Trainer
  452.  
  453.     ; *** the disk routine
  454.  
  455.     PATCHUSRJMP    $7FD8.W,DiskRoutine
  456.  
  457.     ; *** flushes caches
  458.  
  459.     JSRGEN    FlushCachesHard
  460.  
  461.     lea    $DFF000,A6
  462.     move.w    #$7FFF,dmacon(A6)
  463.     move.w    #$7FFF,intena(A6)
  464.  
  465.     jmp    $400.W
  466.  
  467.  
  468. RemoveChecksums:
  469.  
  470.     PATCH_NOPNOP    $30CA.W
  471.     PATCH_NOP    $30CE.W
  472.  
  473.     PATCH_NOPNOP    $3B52.W
  474.     PATCH_NOP    $3B56.W
  475.  
  476.     PATCH_NOPNOP    $16D6
  477.     PATCH_NOP    $16DA
  478.  
  479.     PATCH_NOP    $1F18
  480.  
  481.     rts
  482.  
  483. RemoveChecksums_2D:
  484.     ; those ones were added for v1.4
  485.     ; after having examined the Phil Douglas
  486.     ; SKID ROW cracked version (thanks to him)
  487.  
  488.     PATCH_NOPNOP    $3FCE
  489.     PATCH_NOPNOP    $455C
  490.     PATCH_NOPNOP    $4F08
  491.     PATCH_NOPNOP    $6EB4
  492.     PATCH_NOPNOP    $6ECE
  493.  
  494.     rts
  495.  
  496. RemoveChecksums_Budget:
  497.     ; those ones were added for v1.4
  498.     ; after having examined the Phil Douglas
  499.     ; SKID ROW cracked version (thanks to him)
  500.     ; and adapted to the offset changes recently
  501.  
  502.     PATCH_NOPNOP    $3F28
  503.     PATCH_NOPNOP    $44B6
  504.     PATCH_NOPNOP    $4E62
  505.     PATCH_NOPNOP    $6E0E
  506.     PATCH_NOPNOP    $6E28
  507.     rts
  508.  
  509.  
  510. RemoveProtect_2D_Common:
  511.     move.l    #$0,$8
  512.     move.l    #$7efa,$c
  513.     move.l    #$34c,$10        ; <-- added
  514. ;    move.l    #$682fa0e6,$14        
  515.     move.l    #$330,$24        ; <-- added
  516.     move.l    #$8290ffc1,$60
  517.     move.l    #$fff8,$264
  518.     move.l    #$fff8,$268
  519.     move.l    #$594000cf,$26c
  520.     move.l    #$b0,$270
  521.     move.l    #$1498,$274
  522.     move.l    #$1914,$278
  523.     move.l    #$7a498b40,$27c
  524.     move.l    #$442,$280
  525.     move.l    #$1,$28c
  526.     move.l    #$800002,$290
  527.     move.l    #$3,$298
  528.     move.l    #$fff8,$29c
  529.     move.l    #$594000cf,$2a0
  530.     move.l    #$b0,$2a4
  531.     move.l    #$1498,$2a8
  532.     move.l    #$1914,$2ac
  533.     move.l    #$970f8d2c,$2b0
  534.     move.l    #$a,$2b4
  535.     move.l    #$2,$2c0
  536.     move.l    #$800002,$2c4
  537.     move.l    #$8290ffc1,$2c8        ; important
  538.     move.l    #$3,$2cc
  539.     move.l    #$7b76,$2d0
  540.     move.l    #$dff000,$2d4
  541.     move.l    #$2d8,$2d8
  542.     move.l    #$7e2a,$2dc
  543.     move.l    #$2f3bb76e,$2e0
  544.     move.l    #$2c6f42b2,$2e4
  545.     move.l    #$7a46,$2e8
  546.     move.l    #$21000000,$2ec
  547.     move.l    #$360006c,$2f0
  548.     move.l    #$e1687,$2f4
  549.     move.l    #$8290ffc1,$2f8        ; important
  550.     move.l    #$7e5c,$2fc
  551.     move.l    #$a7080000,$300
  552.     move.l    #$7ab02024,$304
  553.     move.l    #$7aae,$308
  554.     move.l    #$2f3c9dfa,$30c
  555.     move.l    #$8290ffc1,$310        ; imp
  556.     move.l    #$1875a,$314
  557.     move.l    #$a7040000,$318
  558.     move.l    #$9250,$31c
  559.     move.l    #$34c,$320
  560.     move.l    #$a7000000,$324
  561.     move.l    #$7fae2024,$328
  562.     move.l    #$7fa8,$32c
  563.     move.l    #$bd96bdae,$330
  564.     move.l    #$4487a,$334
  565.     move.l    #$1423df,$338
  566.     move.l    #$10,$33c
  567.     move.l    #$4dfaffee,$340
  568.     move.l    #$202e00b8,$344
  569.     move.l    #$4e7b0002,$348
  570.     move.l    #$200a6720,$34c
  571.     move.l    #$b3c86f0c,$350
  572.     move.l    #$d1c0d3c0,$354
  573.     move.l    #$23205980,$358
  574.     move.l    #$66fa6006,$35c
  575.     move.l    #$22d85980,$360
  576.     move.l    #$66fa200b,$364
  577.     move.l    #$67064299,$368
  578.     move.l    #$598066fa,$36c
  579.     move.l    #$2d4c00be,$370
  580.     move.l    #$4fee007c,$374
  581.     move.l    #$4cdf7fff,$378
  582.     move.l    #$584f0257,$37c
  583.     move.l    #$7fff4e73,$380
  584.     move.l    #$bd96bdae,$384
  585.     move.l    #$42c6f,$388
  586.     move.l    #$23c17,$38c
  587.     move.l    #$246a71f,$390
  588.     move.l    #$d246d046,$394
  589.     move.l    #$b186bb86,$398
  590.     move.l    #$bd96bdae,$39c
  591.     move.l    #$4ddb9,$3a0
  592.     move.l    #$10,$3a4
  593.     move.l    #$4e730000,$3a8
  594.     move.l    #$0,$3ac
  595.     move.l    #$0,$3b0
  596.     move.l    #$70004e75,$3b4
  597.     move.l    #$3346,$3b8
  598.     move.l    #$4e754e75,$3bc
  599.     move.l    #$0,$3c0
  600.     move.l    #$222f,$3c4
  601.     move.l    #$1f,$3c8
  602.     move.l    #$8afa,$3cc
  603.     move.l    #$1724a,$3d0
  604.     move.l    #$1874e,$3d4
  605.     move.l    #$7004,$3d8
  606.     move.l    #$a3c6,$3dc
  607.     move.l    #$9e16,$3e0
  608. ;    move.l    #$21000000,$3f0
  609. ;    move.l    #$4f80010,$3f4
  610.     move.l    #$41a0000,$3fc
  611.     rts
  612.  
  613. RemoveProtect_2DTIMO:
  614.     bsr    RemoveProtect_2D_Common
  615.  
  616.     move.l    #$1001FF00,$84c4
  617.     move.l    #$10A0000,$86d0
  618.     move.l    #$FFFFFFFE,$8AC4
  619.     move.l    #$70616e65,$9D3C
  620.     move.l    #$75578,$9d70
  621.     move.l    #$3C,$9E4C
  622.     move.l    #$FC9C0000,$9E64
  623.     move.l    #$3C,$9E78
  624.     move.l    #$3F440000,$9E94
  625.     move.l    #$1,$CDA4
  626.     move.l    #$30002,$CDA8
  627.     move.l    #$3C00020,$140B4
  628.     move.l    #$33000C,$140B8
  629.     rts
  630.  
  631. RemoveProtect_2D:
  632.     bsr    RemoveProtect_2D_Common
  633.     move.l    #$3f801001,$84c8
  634.     move.l    #$ff0000e0,$84cc
  635.     move.l    #$24010a,$86d4
  636.     move.l    #$120,$86d8
  637.     move.l    #$ffff,$8ac8
  638.     move.l    #$fffe1001,$8acc
  639.     move.l    #$1fc07061,$9d40
  640.     move.l    #$6e656c31,$9d44
  641.     move.l    #$7,$9d74
  642.     move.l    #$55780007,$9d78
  643.     move.l    #$3d,$9db0
  644.     move.l    #$3d8a0000,$9db4
  645.     move.l    #$c40000ff,$9e3c
  646.     move.l    #$6e0000,$9e54
  647.     move.l    #$a,$9e64
  648.     move.l    #$a26d,$9e68
  649.     move.l    #$6e0000,$9e80
  650.     move.l    #$3f12,$9e98
  651.     move.l    #$10003,$cdac
  652.     move.l    #$200033,$140bc
  653.     move.l    #$613c7100,$14308
  654.     move.l    #$613c7100,$14350
  655.     move.l    #$59387800,$145f4
  656.     move.l    #$59387880,$1467c
  657.     move.l    #$59407800,$14704
  658.     move.l    #$59407880,$1478c
  659.     move.l    #$59387800,$14814
  660.     move.l    #$59387880,$1489c
  661.     move.l    #$59407800,$14924
  662.     move.l    #$59407880,$149ac
  663.     move.l    #$59407880,$149ac
  664.     rts
  665.  
  666.  
  667. ; *** Loading routine. Common to all lemmings versions
  668.  
  669. DiskRoutine:
  670.     cmp.b    #5,D1
  671.     beq    DR_DirRead
  672.     cmp.b    #0,D1
  673.     beq    DR_FileRead
  674.  
  675.     moveq.l    #0,D0
  676.     bra    DR_End
  677.  
  678.     ; *** load the file
  679.  
  680. DR_FileRead:
  681.     moveq.l    #0,D0
  682.     moveq.l    #-1,D1
  683.  
  684.     JSRGEN    ReadFile
  685.     tst.l    D0
  686.     bmi    DR_NotFound
  687.  
  688.     bsr    correct_code
  689.  
  690.     moveq.l    #0,D0
  691.     bra    DR_End
  692.  
  693. ; *** read directory
  694.  
  695. DR_DirRead:
  696.     moveq.l    #0,D0
  697.     moveq.l    #0,D1
  698. DR_End:
  699.     MOVEM.L    (A7)+,D2-D7/A0-A6
  700.     RTS
  701.  
  702. DR_NotFound:
  703.     lea    FileError(pc),A0
  704.     JSRGEN    SetExitRoutine
  705.     JSRGEN    InGameExit
  706.     move.w    #$F00,$DFF180
  707.     bra    DR_NotFound
  708.  
  709. ; *** other commands, still not supported
  710.  
  711. DR_Other:
  712.     JSRGEN    WaitMouse
  713.     illegal
  714.     bra    DR_Other
  715.  
  716. ; *** a bug when ripping the files of the 2D NTSC version
  717. ; *** zeroed the first $1000 bytes of the 'code' file
  718. ; *** lets correct it
  719.  
  720. correct_code:
  721.     tst.l    (A1)        ; first long = 0? strange...
  722.     bne    exit$
  723.  
  724.     STORE_REGS
  725.  
  726.     GETUSRADDR    codename
  727.     move.l    A0,D1
  728.     JSRGEN    StrcmpAsm
  729.     tst.l    D0
  730.     bne    nothing$
  731.  
  732.     lea    codesmpl(pc),A0
  733.     ; *** dest buffer in A1
  734.     move.w    #$3FF,D0
  735.  
  736. copy$
  737.     move.l    (A0)+,(A1)+
  738.     dbf    D0,copy$
  739.  
  740. nothing$
  741.     RESTORE_REGS
  742. exit$
  743.     rts
  744.  
  745.  
  746. ; **** Remove protection (budget version)
  747.  
  748. RemoveProtect_Budget:    
  749. ;    move.w    #$8210,$DFF096
  750. ;    JSR    $7598.W        ;    protection
  751.  
  752.     move.l    #$0,$8
  753.     move.l    #$7e54,$c
  754.     move.l    #$34c,$10
  755. ;    move.l    #$682ff9b6,$14
  756.     move.l    #$330,$24
  757.     move.l    #$8290ffc1,$60
  758.     move.l    #$fff8,$264
  759.     move.l    #$fff8,$268
  760.     move.l    #$1c4000cf,$26c
  761.     move.l    #$b0,$270
  762.     move.l    #$1498,$274
  763.     move.l    #$1914,$278
  764.     move.l    #$7a498b40,$27c
  765.     move.l    #$245,$280
  766.     move.l    #$0,$288
  767.     move.l    #$fff8,$28c
  768.     move.l    #$1c4000cf,$290
  769.     move.l    #$b0,$294
  770.     move.l    #$1498,$298
  771.     move.l    #$1914,$29c
  772.     move.l    #$1,$2a0
  773.     move.l    #$0,$2a4
  774.     move.l    #$0,$2a8
  775.     move.l    #$0,$2ac
  776.     move.l    #$0,$2b0
  777.     move.l    #$800002,$2b4
  778.     move.l    #$8290ffc1,$2b8
  779.     move.l    #$3,$2bc
  780.     move.l    #$7db2,$2c0
  781.     move.l    #$dff000,$2c4
  782.     move.l    #$2d8,$2c8
  783.     move.l    #$7d84,$2cc
  784.     move.l    #$2f3bb76e,$2d0
  785.     move.l    #$2c6f42b2,$2d4
  786.     move.l    #$79a0,$2d8
  787.     move.l    #$21000000,$2dc
  788.     move.l    #$348006c,$2e0
  789.     move.l    #$0,$2e4
  790.     move.l    #$0,$2e8
  791.     move.l    #$77,$2ec
  792.     move.l    #$77,$2f0
  793.     move.l    #$e1687,$2f4
  794.     move.l    #$8290ffc1,$2f8
  795.     move.l    #$7db6,$2fc
  796.     move.l    #$a7080000,$300
  797.     move.l    #$7a0a2024,$304
  798.     move.l    #$7a08,$308
  799.     move.l    #$2f3c9dfa,$30c
  800.     move.l    #$8290ffc1,$310
  801.     move.l    #$186b4,$314
  802.     move.l    #$a7040000,$318
  803.     move.l    #$9250,$31c
  804.     move.l    #$34c,$320
  805.     move.l    #$a7000000,$324
  806.     move.l    #$7f082024,$328
  807.     move.l    #$7f02,$32c
  808.     move.l    #$bd96bdae,$330
  809.     move.l    #$4487a,$334
  810.     move.l    #$1423df,$338
  811.     move.l    #$10,$33c
  812.     move.l    #$4dfaffee,$340
  813.     move.l    #$202e00b8,$344
  814.     move.l    #$4e7b0002,$348
  815.     move.l    #$200a6720,$34c
  816.     move.l    #$b3c86f0c,$350
  817.     move.l    #$d1c0d3c0,$354
  818.     move.l    #$23205980,$358
  819.     move.l    #$66fa6006,$35c
  820.     move.l    #$22d85980,$360
  821.     move.l    #$66fa200b,$364
  822.     move.l    #$67064299,$368
  823.     move.l    #$598066fa,$36c
  824.     move.l    #$2d4c00be,$370
  825.     move.l    #$4fee007c,$374
  826.     move.l    #$4cdf7fff,$378
  827.     move.l    #$584f0257,$37c
  828.     move.l    #$7fff4e73,$380
  829.     move.l    #$bd96bdae,$384
  830.     move.l    #$42c6f,$388
  831.     move.l    #$23c17,$38c
  832.     move.l    #$246a71f,$390
  833.     move.l    #$d246d046,$394
  834.     move.l    #$b186bb86,$398
  835.     move.l    #$bd96bdae,$39c
  836.     move.l    #$4ddb9,$3a0
  837.     move.l    #$10,$3a4
  838.     move.l    #$4e730000,$3a8
  839.     move.l    #$0,$3ac
  840.     move.l    #$0,$3b0
  841.     move.l    #$70004e75,$3b4
  842.     move.l    #$3346,$3b8
  843.     move.l    #$4e754e75,$3bc
  844.     move.l    #$0,$3c0
  845.     move.l    #$222f,$3c4
  846.     move.l    #$f,$3c8
  847.     move.l    #$8a54,$3cc
  848.     move.l    #$171a4,$3d0
  849.     move.l    #$186a8,$3d4
  850.     move.l    #$6f5e,$3d8
  851.     move.l    #$a320,$3dc
  852.     move.l    #$9d70,$3e0
  853. ;**    move.l    #$21000000,$3f0
  854. ;**    move.l    #$4f80010,$3f4
  855.     move.l    #$41a0000,$3fc        ; blocker bug without this
  856.     move.l    #$1001ff00,$8424
  857.     move.l    #$10a0000,$8630
  858.     move.l    #$fffffffe,$8a24
  859.     move.l    #$70616e65,$9c9c
  860.     move.l    #$75578,$9cd0
  861.     move.l    #$c400,$9d94
  862.     move.l    #$86,$9dac
  863.     move.l    #$a0000,$9dc0
  864.     move.l    #$4f250000,$9dc4
  865.     move.l    #$86,$9dd8
  866.     move.l    #$3efa0000,$9df4
  867.     move.l    #$1,$cd04
  868.     move.l    #$30002,$cd08
  869.     move.l    #$3c00020,$14014
  870.     move.l    #$33000c,$14018
  871.     move.l    #$33000c,$14018
  872.  
  873.     rts
  874.  
  875. copyblock:
  876. copy$
  877.     move.l    (A1)+,(A0)+
  878.     cmp.l    A1,A2
  879.     bne    copy$
  880.     rts
  881.  
  882.  
  883.  
  884.     ; ** in case the user tries to run the game without having installed
  885.     ; ** the game properly
  886.  
  887. MainErr:
  888.     Mac_printf    "** File ''main'' missing or game not installed."
  889.     Mac_printf    "   Please install the game properly and try again !!"
  890.     JMPABS    CloseAll
  891.  
  892. VerErr:
  893.     bsr    DisplayVerText
  894.     JMPABS    CloseAll
  895.  
  896. VerErr2:
  897.     bsr    DisplayVerText
  898.     NEWLINE
  899.     Mac_printf    "   Press RETURN to exit"
  900.     JSRABS    WaitReturn
  901.     JMPABS    CloseAll
  902.  
  903. DisplayVerText:
  904.     Mac_printf    "** Sorry but the version you installed is not"
  905.     Mac_printf    "   supported yet. Supported versions are:"
  906.     Mac_printf    "   Lemmings Budget (PAL), Oh No More Lemmings (NTSC),"
  907.     Mac_printf    "   Lemmings 2 Disks (PAL), Oh No More Lemmings (PAL),"
  908.     Mac_printf    "   Oh No More Lemmings (PAL) V2, Lemmings 2 Disks (NTSC)"
  909.     Mac_printf    "   Oh No More Lemmings (PAL) V3 !"
  910.     rts
  911.  
  912. FileError:
  913.     Mac_printf    "** At least one file is missing. Reinstall game"
  914.     Mac_printf    "   Press RETURN to exit"
  915.     JSRABS    WaitReturn
  916.     rts
  917.  
  918. ; *** detects versions. Oh no PAL and NTSC not differencied here (assuming NTSC)
  919.  
  920. GetVersion:
  921.     lea    mainname(pc),A0
  922.     lea    main_buf(pc),A1
  923.     moveq.l    #0,D0
  924.     moveq.l    #2,D1
  925.     move.l    #$44,D2
  926.     JSRGEN    ReadFilePartHD
  927.     tst.l    D0
  928.     bne    MainErr
  929.  
  930.     move.w    main_buf(pc),D0
  931.     cmp.w    #$06E6,D0
  932.     bne    not_bud$
  933.     RELOC_MOVEL    #VER_BUDGET,version
  934.     bra    exit$
  935.  
  936. not_bud$
  937.     cmp.w    #$0742,D0
  938.     bne    not_mor$
  939.     RELOC_MOVEL    #VER_MORE_NTSC,version
  940.     bra    exit$
  941.  
  942. not_mor$
  943.     cmp.w    #$37DF,D0
  944.     bne    not_2dp$
  945.     RELOC_MOVEL    #VER_2D_PAL,version
  946.     bra    exit$
  947. not_2dp$
  948.     cmp.w    #$37DC,D0
  949.     bne    not_2dt$
  950.  
  951.     RELOC_MOVEL    #VER_2D_TIMO,version
  952.     bra    exit$
  953.  
  954. not_2dt$
  955.     bra    VerErr
  956. exit$
  957.     rts
  958.  
  959.  
  960. trainer:
  961.     dc.l    0
  962. version:
  963.     dc.l    0
  964. ExtBase:
  965.     dc.l    0
  966. ExtSize:
  967.     dc.l    0
  968. ExtFlag:
  969.     dc.l    0
  970. mainname:
  971.     dc.b    "main",0
  972. codename:
  973.     dc.b    "code",0
  974.  
  975.     cnop    0,4
  976. Decrunch:
  977.     bsr    DecRoutine
  978.     STORE_REGS
  979.     move.l    #$082E000E,D0
  980.     move.l    #$082E0006,D1
  981.     lea    $7BB5A,A0
  982.     lea    $7CAE0,A1
  983.     JSRGEN    HexReplaceLong
  984.     RESTORE_REGS
  985.     JSRGEN    FlushCachesHard
  986.     RTS
  987.  
  988. DecRoutine:
  989.     ADDA.L    D0,A0            ;00: D1C0
  990.     MOVEA.L    -(A0),A2        ;02: 2460
  991.     ADDA.L    A1,A2            ;04: D5C9
  992.     MOVE.L    -(A0),D5        ;06: 2A20
  993.     MOVE.L    -(A0),D0        ;08: 2020
  994.     EOR.L    D0,D5            ;0A: B185
  995. LAB_0000:
  996.     LSR.L    #1,D0            ;0C: E288
  997.     BNE.S    LAB_0001        ;0E: 6604
  998.     BSR    LAB_000E        ;10: 61000084
  999. LAB_0001:
  1000.     BCS.S    LAB_0008        ;14: 653A
  1001.     MOVEQ    #8,D1            ;16: 7208
  1002.     MOVEQ    #1,D3            ;18: 7601
  1003.     LSR.L    #1,D0            ;1A: E288
  1004.     BNE.S    LAB_0002        ;1C: 6604
  1005.     BSR    LAB_000E        ;1E: 61000076
  1006. LAB_0002:
  1007.     BCS.S    LAB_000A        ;22: 6554
  1008.     MOVEQ    #3,D1            ;24: 7203
  1009.     MOVEQ    #0,D4            ;26: 7800
  1010. LAB_0003:
  1011.     BSR    LAB_000F        ;28: 61000078
  1012.     MOVE    D2,D3            ;2C: 3602
  1013.     ADD    D4,D3            ;2E: D644
  1014. LAB_0004:
  1015.     MOVEQ    #7,D1            ;30: 7207
  1016. LAB_0005:
  1017.     LSR.L    #1,D0            ;32: E288
  1018.     BNE.S    LAB_0006        ;34: 6604
  1019.     BSR    LAB_000E        ;36: 6100005E
  1020. LAB_0006:
  1021.     ROXL.L    #1,D2            ;3A: E392
  1022.     DBF    D1,LAB_0005        ;3C: 51C9FFF4
  1023.     MOVE.B    D2,-(A2)        ;40: 1502
  1024.     DBF    D3,LAB_0004        ;42: 51CBFFEC
  1025.     BRA    LAB_000C        ;46: 6000003E
  1026. LAB_0007:
  1027.     MOVEQ    #8,D1            ;4A: 7208
  1028.     MOVEQ    #8,D4            ;4C: 7808
  1029.     BRA.S    LAB_0003        ;4E: 60D8
  1030. LAB_0008:
  1031.     MOVEQ    #2,D1            ;50: 7202
  1032.     BSR    LAB_000F        ;52: 6100004E
  1033.     CMP.B    #$02,D2            ;56: B43C0002
  1034.     BLT.S    LAB_0009        ;5A: 6D14
  1035.     CMP.B    #$03,D2            ;5C: B43C0003
  1036.     BEQ.S    LAB_0007        ;60: 67E8
  1037.     MOVEQ    #8,D1            ;62: 7208
  1038.     BSR    LAB_000F        ;64: 6100003C
  1039.     MOVE    D2,D3            ;68: 3602
  1040.     MOVEQ    #12,D1            ;6A: 720C
  1041.     BRA    LAB_000A        ;6C: 6000000A
  1042. LAB_0009:
  1043.     MOVEQ    #9,D1            ;70: 7209
  1044.     ADD    D2,D1            ;72: D242
  1045.     ADDQ    #2,D2            ;74: 5442
  1046.     MOVE    D2,D3            ;76: 3602
  1047. LAB_000A:
  1048.     BSR    LAB_000F        ;78: 61000028
  1049. LAB_000B:
  1050.     SUBQ.L    #1,A2            ;7C: 538A
  1051.     MOVE.B    0(A2,D2.W),(A2)        ;7E: 14B22000
  1052.     DBF    D3,LAB_000B        ;82: 51CBFFF8
  1053. LAB_000C:
  1054.     CMPA.L    A2,A1            ;86: B3CA
  1055.     BLT.S    LAB_0000        ;88: 6D82
  1056.     TST.L    D5            ;8A: 4A85
  1057.     BNE.S    LAB_000D        ;8C: 6602
  1058.     RTS                ;8E: 4E75
  1059. LAB_000D:
  1060.     JSRGEN    InGameExit
  1061.     bra    LAB_000D
  1062. LAB_000E:
  1063.     MOVE.L    -(A0),D0        ;96: 2020
  1064.     EOR.L    D0,D5            ;98: B185
  1065.     MOVE    #$0010,CCR        ;9A: 44FC0010
  1066.     ROXR.L    #1,D0            ;9E: E290
  1067.     RTS                ;A0: 4E75
  1068. LAB_000F:
  1069.     SUBQ    #1,D1            ;A2: 5341
  1070.     MOVEQ    #0,D2            ;A4: 7400
  1071. LAB_0010:
  1072.     LSR.L    #1,D0            ;A6: E288
  1073.     BNE.S    LAB_0011        ;A8: 660A
  1074.     MOVE.L    -(A0),D0        ;AA: 2020
  1075.     EOR.L    D0,D5            ;AC: B185
  1076.     MOVE    #$0010,CCR        ;AE: 44FC0010
  1077.     ROXR.L    #1,D0            ;B2: E290
  1078. LAB_0011:
  1079.     ROXL.L    #1,D2            ;B4: E392
  1080.     DBF    D1,LAB_0010        ;B6: 51C9FFEE
  1081.     RTS                ;BA: 4E75
  1082.  
  1083. codesmpl:
  1084.     incbin    "codesmpl.bin"
  1085.  
  1086.     cnop    0,4    
  1087. main_buf:
  1088.     dc.l    0,0
  1089.